Smile provides some useful coercions. To use them, your script must be running under Smile.
Coercions for scripts
You can make a script into a string, and a string into a script. This allows for dynamical script editing (in other terms, making or changing a script by script).
----------------------------
set script of window 1 to "-- aaargh !"
----------------------------
This simple example replaces the object script of the active window.
----------------------------
display dialog (script of window 1 as text)
----------------------------
This will display the script of the active window in a dialog box (provided it is not too long).
Turning things into string
The "display" command, part of the Smile Dictionary, coerces any arbitrary reference to text. For instance, you can turn a list into its usual string representation :
• If "display" does not seem to be able to coerce some expression into text, try making the expression a list's item (this powerful trick has been pointed out by J-P Pellet).
----------------------------
display ({application "Finder"})
----------------------------
• Smile can make any of its objects into a record, which contains all its properties, except its script.
----------------------------
window 1 as record
----------------------------
Note that you can get a more complete record, containing all the data needed to clone the object, by using the command "whole". (Use this example with care).
----------------------------
make basic object with properties (get whole of window 1):
----------------------------
• Smile can make any property of "every ..." into a list. The plural can be used instead of the "every" keyword.
----------------------------
windows as list --> returns the list of the opened windows
----------------------------
----------------------------
name of windows --> returns the list of the names of the opened windows
----------------------------
• When working in Smile, you can get the four-character codes of the object classes.